package ref;

/**
 * @author Mark
 * @date 2020/5/24 21:40
 * @description 反射类
 */
public class RefClass {

    public static void main(String[] args) throws ClassNotFoundException {

        // 第一种方式
        Class<?> aClass = Class.forName("ref.User");
        System.out.println(aClass.hashCode());

        // 第二种方式
        Class<User> userClass = User.class;
        System.out.println(userClass.hashCode());

        // 第三种方式
        Class aClass1 = new User().getClass();
        System.out.println(aClass1.hashCode());

    }

}

class User {

    private String name;

    private int age;

    private int id;


    User() {
    }

    public User(String name, int age, int id) {
        this.name = name;
        this.age = age;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                '}';
    }

}
